<?php
require_once('../qcubed/includes/configuration/prepend.inc.php');
require_once('../build/includes/config.php');
require_once('lookups.php');

$page = $_GET['page']; // get the requested page 
$limit = $_GET['rows']; // get how many rows we want to have into the grid 
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort 
$sord = $_GET['sord']; // get the direction

if (isset($_SESSION["activeprojectid"])) {
	$projectid = intval($_SESSION["activeprojectid"]);

	$bugs = MantisBugTable::LoadArrayByProjectId($projectid);
} else {
	$bugs = MantisBugTable::LoadAll();
}

?><<?php echo '?'; ?>xml version ="1.0" encoding="utf-8"?>
<rows>
  <page><?php echo $page; ?></page>
  <total><?php echo intVal(count($bugs) / $limit + ((count($bugs) % $limit > 0) ? 1 : 0)); ?></total>
  <records><?php echo count($bugs); ?></records>
<?php
for ($i=0; $i<count($bugs); $i++) {
	?>
	<row id='<?php echo $bugs[$i]->Id; ?>'>
      <cell><?php echo $bugs[$i]->Id; ?></cell>
      <cell><?php echo $bugs[$i]->Summary; ?></cell>
      <cell><?php echo  user($bugs[$i]->HandlerId); ?></cell>
      <cell><?php echo $g_priority[$bugs[$i]->Priority]; ?></cell>
      <cell><?php echo $g_severity[$bugs[$i]->Severity]; ?></cell>
      <cell><?php echo $g_status[$bugs[$i]->Status]; ?></cell>
      <cell><?php echo category($bugs[$i]->CategoryId); ?></cell>
      <cell><?php echo QDateTime::FromTimestamp(
		$bugs[$i]->DateSubmitted
			)->qFormat('MMM DD YYYY', QDateTime::Now()->GetTimeZone()); ?></cell>
      <cell><?php echo QDateTime::FromTimestamp(
		$bugs[$i]->LastUpdated
			)->qFormat('MMM DD YYYY', QDateTime::Now()->GetTimeZone()); ?></cell>
    </row>
<?php
}
?>
</rows>